const JSONbig = require('json-bigint')({"storeAsString": true})
const session = {
  sessionStorage: window.sessionStorage,
  set: function(key, value) {
    if (typeof value === 'object') {
      value = JSONbig.stringify(value)
    }
    this.sessionStorage.setItem(key, value)
  },
  get: function(key) {
    const value = this.sessionStorage.getItem(key) || ''
    try {
      return JSONbig.parse(value)
    } catch (e) {
      return value
    }
  },
  remove: function(key) {
    this.sessionStorage.removeItem(key)
  },
  clear: function() {
    this.sessionStorage.clear()
  }
}

export default session
